<?php
class User_model extends CI_Model {
	
	public function validate_login($u, $p) {
		$q = $this->db->get_where ( 'users', array ('username' => $u, 'password' => md5 ($p)   ) );
		if ($q->num_rows ()) {
			$data = $q->row_array ();
			$this->session->set_userdata ( 'username', $data ['username'] );
			$_SESSION['username'] = $data['username'];
			$q->free_result ();
			return TRUE;
		} else {
			$q->free_result ();
			return FALSE;
		}
	}
	public function register() {
		$data = array ('username' => $_POST ['username'], 'password' => md5($_POST ['password']), 'lastname' => $_POST ['lname'], 'firstname' => $_POST ['fname'], 'type' => '1', 'public' => '1' );
		$q = $this->db->insert ( 'users', $data );
		$q1 = $this->db->get_where ( 'users', array ('username' => $_POST ['username'] ) );
		if ($q1->num_rows ()) {
			$data1 = $q1->row_array ();
		}
		$q1->free_result ();
		$data2 = array ('user_id' => $data1 ['id'], 'address' => $_POST ['address'], 'city' => $_POST ['city'], 'state' => $_POST ['state'], 'country' => $_POST ['country'], 'email' => $_POST ['email'] );
		$q3 = $this->db->insert('address',$data2);
	}

}